<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<h3>已生成一个1~100之间的随机整数:</h3>
<input type="text" placeholder="请输入你猜的数字">
<button onclick="guess()">点我验证</button>
<h3>小提示:<span></span></h3>
<script>
    let r=parseInt(Math.random()*100)+1;
    console.log('打个小抄:'+r)
    let num=0;
    function guess(){
        num++;
        var inputE = document.querySelector('input');
        var spanE=document.querySelector('span');
        let n=parseFloat(inputE.value)
        if(n>r){
            spanE.innerHTML="猜大了!"
        }else if(n<r){
            spanE.innerHTML="猜小了!"
        }else {
            spanE.innerHTML="恭喜你只用了"+num+"次就猜对了!"
        }
    }


</script>
</body>
</html>